
import { createCanvas, loadImage } from 'canvas';
import fs from 'fs';
export async function combineImages(backgroundPath: string, foregroundPath: string, outputPath: string) {
  try {
    const background = await loadImage(backgroundPath);
    const foreground = await loadImage(foregroundPath);

    const canvas = createCanvas(background.width, background.height);
    const ctx = canvas.getContext('2d');

    // 将背景图绘制到画布上
    ctx.drawImage(background, 0, 0);

    // 计算前景图像在背景上的位置
    const x = 1886;
    const y = 890;

    // 将前景图像绘制到画布上
    ctx.drawImage(foreground, x, y);

    // 输出图片到文件
    canvas.createJPEGStream().pipe(fs.createWriteStream(outputPath));

  } catch (error) {
    console.error('Error combining images:', error);
  }
}